package com.ogawa.a7517;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;

import com.example.reslib.utils.PreferenceWrapper;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.ogawa.a7517.activity.MainActivity7517;
import com.ogawa.a7517.bean.ProgramBean;

import java.util.ArrayList;
import java.util.List;

public class DataManager {
    private static DataManager mInst = null;
    private static Object mLock = new Object();
    private List<ProgramBean> programBeans;
    private MainActivity7517 activity;
    private Gson mGson = new Gson();
    private boolean isSnChange;

    private DataManager() {
    }

    public static DataManager getInst() {
        if (mInst == null) {
            synchronized (mLock) {
                mInst = new DataManager();
            }
        }
        return mInst;

    }

    public List<Integer> getCollections() {
        String collections = new PreferenceWrapper().getStringValue(Constant.COLLECTIONS, "");
        if (TextUtils.isEmpty(collections)) {
            return new ArrayList<>();
        } else {
            return mGson.fromJson(collections, new TypeToken<List<Integer>>() {
            }.getType());
        }
    }

    public void setCollections(List<Integer> collections) {
        new PreferenceWrapper().setStringValueAndCommit(Constant.COLLECTIONS, mGson.toJson(collections));
    }

    public boolean isSnChange() {
        return isSnChange;
    }

    public void setSnChange(boolean snChange) {
        isSnChange = snChange;
    }

    public MainActivity7517 getActivity() {
        return activity;
    }

    public void setActivity(MainActivity7517 activity) {
        this.activity = activity;
    }

    public void initPrograms(Context context) {
        programBeans = new ArrayList<>();
        programBeans.add(new ProgramBean(R.drawable.selector_btn_shangban, context.getString(R.string.program_sbz), 1));
        programBeans.add(new ProgramBean(R.drawable.selector_btn_jianjing, context.getString(R.string.program_jjzd), 2));
        programBeans.add(new ProgramBean(R.drawable.selector_btn_jiache, context.getString(R.string.program_jcz), 3));
        programBeans.add(new ProgramBean(R.drawable.selector_btn_jizhu, context.getString(R.string.program_jzsy), 4));
        programBeans.add(new ProgramBean(R.drawable.selector_btn_ditou, context.getString(R.string.program_dtz), 5));
        programBeans.add(new ProgramBean(R.drawable.selector_btn_yaotun, context.getString(R.string.program_ytyh), 6));
        programBeans.add(new ProgramBean(R.drawable.selector_btn_gaogen, context.getString(R.string.program_ggz), 7));
        programBeans.add(new ProgramBean(R.drawable.selector_btn_xiaotui, context.getString(R.string.program_xtjz), 8));
        programBeans.add(new ProgramBean(R.drawable.selector_btn_nvwang, context.getString(R.string.program_nsmt), 9));
        programBeans.add(new ProgramBean(R.drawable.selector_btn_yuanqi, context.getString(R.string.program_yqfs), 10));
        programBeans.add(new ProgramBean(R.drawable.selector_btn_man, context.getString(R.string.program_nsjt), 11));
        programBeans.add(new ProgramBean(R.drawable.selector_btn_shuimian, context.getString(R.string.program_smms), 12));
        programBeans.add(new ProgramBean(R.drawable.selector_btn_laonian, context.getString(R.string.program_lnys), 13));
        programBeans.add(new ProgramBean(R.drawable.selector_btn_kuaisu, context.getString(R.string.program_ksfs), 14));
        programBeans.add(new ProgramBean(R.drawable.selector_btn_yundong, context.getString(R.string.program_ydhf), 15));
        programBeans.add(new ProgramBean(R.drawable.selector_btn_taishi, context.getString(R.string.program_tsls), 16));
    }

    public List<ProgramBean> getProgramBeans() {
        return programBeans;
    }
}
